package PropsObject;

import com.sxt.GameWin;

import java.awt.*;
import java.util.Random;

public class BulletPropsObj extends PropsObject{
    public BulletPropsObj() {
        super();
    }

    public BulletPropsObj(String image, int x, int y, int width, int height, int speedY, GameWin frame) {
        super(image, x, y, width, height, speedY, frame);
    }


    public BulletPropsObj(String image, GameWin frame) {
        super(image, frame);
    }

    public BulletPropsObj(String image, int x, int y, int speedY, GameWin frame) {
        super(image, x, y, speedY, frame);
    }

    @Override
    public void paintSelf(Graphics s) {
        s.drawImage(image,x,y,null);
        existTime--;
        if (existTime<=0){
            this.Frame.PropsisExist = false;
            this.Frame.removeList.add(this);
        }
        //控制道具移动
        if (x>GameWin.WINDOW_WIDTH - PROPS_WIDTH){
            this.speedX = random.nextInt(10)+1;
            speedX*=-1;
        }
        if (x<0){
            this.speedX = random.nextInt(10)+1;
        }
        if (y>GameWin.WINDOW_HEIGHT - PROPS_HEIGHT){
            this.speedY = random.nextInt(5)+1;
            speedY*=-1;
        }
        if (y<0){
            this.speedY = random.nextInt(5)+1;
        }
        x+=speedX;
        y+=speedY;

    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(x,y,PROPS_WIDTH,PROPS_HEIGHT);
    }
    @Override
    public void DeBug() {
        System.out.println("is BulletProps Object");
    }
}
